{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "gpuType": "T4",
      "authorship_tag": "ABX9TyMG5mNUofZgvGmATsrGBJz5",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/cwyalpha/Langchain-Chatchat-Colab/blob/main/Langchain_chatchat_Qwen1_5_1_8B_colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "%cd /content/\n",
        "!git clone https://github.com/chatchat-space/Langchain-Chatchat.git\n",
        "%cd /content/Langchain-Chatchat/\n",
        "!pip install -r requirements.txt\n",
        "!pip install -r requirements_api.txt\n",
        "!pip install -r requirements_webui.txt\n",
        "!pip install transformers --upgrade\n",
        "!pip install accelerate\n",
        "\n",
        "import torch\n",
        "EMBEDDING_DEVICE = \"cuda\" if torch.cuda.is_available() else \"mps\" if torch.backends.mps.is_available() else \"cpu\"\n",
        "# 首先确认输出是cuda，否则Runtime里类型要改成T4 GPU\n",
        "print(EMBEDDING_DEVICE)\n",
        "\n",
        "!git lfs install\n",
        "!git clone https://huggingface.co/Qwen/Qwen1.5-1.8B-Chat\n",
        "\n",
        "!python copy_config_example.py\n",
        "!sed -i '/^LLM_MODELS.*chatglm3-6b/s/chatglm3-6b/Qwen1.5-1.8B-Chat/' /content/Langchain-Chatchat/configs/model_config.py\n",
        "\n",
        "!python init_database.py --recreate-vs\n",
        "\n",
        "!nohup python startup.py -a &\n",
        "\n",
        "# 最后一步nohup运行之后，需要等待一段时间网页内才有内容\n",
        "# 在/content/Langchain-Chatchat/nohup.out中看到0.0.0.0:8501后就可以正常访问\n",
        "import urllib\n",
        "print(\"Password/Enpoint IP for localtunnel is:\",urllib.request.urlopen('https://ipv4.icanhazip.com').read().decode('utf8').strip(\"\\n\"))\n",
        "!npm install localtunnel\n",
        "#!streamlit run app.py &>web_logs.txt &\n",
        "!npx localtunnel --port 8501\n",
        "# 在网页中输入IP后提交"
      ],
      "metadata": {
        "id": "xIvNEz-7W9-O"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}